require('./entity/pool.typeorm')

var express = require('express');
var app = express();
 
app.get('/*', async function (req, res) {

  let path = req.url;

  let jsfile;
  try{
    jsfile = require("."+ path);
  }catch(e){
    res.send("不存在该方法")
  }
  

  console.log(jsfile, jsfile.faas);

  if(!jsfile || !jsfile.faas){
    res.send("不存在该方法")
  }

  let resdata = await jsfile.faas();
  console.log(resdata);

  res.send(resdata);
})
//  POST 请求
app.post('/*', function (req, res) {
  console.log(req);

  console.log("主页 POST 请求");
  res.send('Hello POST');
})
 
var server = app.listen(8066, function () {
 
  var host = server.address().address
  var port = server.address().port
 
  console.log("应用实例，访问地址为 http://%s:%s", host, port)
 
})